﻿#include "cmd_shade.h"
#include "ais/ais_camera.h"
#include "ais/ais_light.h"

CAGD::CmdStatus CAGD::CmdCamera::Step(char c)
{
    if (c == 'l')
    {
        // 捕获点击点
        auto P = m_context.GetInfo().points[0];
        auto Q = m_context.GetSpacePoint(P);
        auto HQ = Handle(GeomPoint)(new GeomPoint(Q));
        auto obj = Handle(AIS_Camera)(new AIS_Camera(HQ));
        m_context.CreateObject(obj);

        return CmdStatus::STEP;
    }

    return CmdStatus::KEEP;
}

CAGD::CmdStatus CAGD::CmdPointLight::Step(char c)
{
    if (c == 'l')
    {
        // 捕获点击点
        auto P = m_context.GetInfo().points[0];

        // 设置光源信息
        Light light;
        light.position = m_context.GetSpacePoint(P);
        light.ambient = {0.5f, 0.5f, 0.5f};
        light.diffuse = {0.4f, 0.4f, 0.4f};
        light.specular = {0.8f, 0.8f, 0.8f};

        auto obj = Handle(AIS_PointLight)(new AIS_PointLight(light));
        m_context.CreateObject(obj);

        return CmdStatus::STEP;
    }

    return CmdStatus::KEEP;
}

CAGD::CmdStatus CAGD::CmdDirLight::Step(char c)
{
    if (c == 'l')
    {
        // 捕获点击点
        auto P = m_context.GetInfo().points[0];

        // 设置光源信息
        Light light;
        light.position = m_context.GetSpacePoint(P);
        light.direction = -light.position * 0.1;
        light.ambient = {0.5f, 0.5f, 0.5f};
        light.diffuse = {0.4f, 0.4f, 0.4f};
        light.specular = {0.8f, 0.8f, 0.8f};

        auto obj = Handle(AIS_DirLight)(new AIS_DirLight(light));
        m_context.CreateObject(obj);

        return CmdStatus::STEP;
    }

    return CmdStatus::KEEP;
}

CAGD::CmdStatus CAGD::CmdSpotLight::Step(char c)
{
    if (c == 'l')
    {
        // 捕获点击点
        auto P = m_context.GetInfo().points[0];

        // 设置光源信息
        Light light;
        light.position = m_context.GetSpacePoint(P);
        light.direction = -light.position * 0.1;
        light.ambient = {0.5f, 0.5f, 0.5f};
        light.diffuse = {0.4f, 0.4f, 0.4f};
        light.specular = {0.8f, 0.8f, 0.8f};

        auto obj = Handle(AIS_SpotLight)(new AIS_SpotLight(light));
        m_context.CreateObject(obj);

        return CmdStatus::STEP;
    }

    return CmdStatus::KEEP;
}
